<?php
namespace app\index\model;

use think\Model;

class User extends Model{
    //登录查询
    public function checkUser($userId,$password){
        $data = $this->where('userId',$userId)->find();
        if(!empty($data)){
            $data = $data->toArray();
            if($data['password']!=$password){
                return "密码错误!";
            }else{
                //var_dump($data);
                return $data; 
            }
        }else{
            return "账号不存在!";
        }
    }

    //注册
    public function addUser($userId,$username,$password,$userstatus){
        $data = $this->where('userId',$userId)->where('userstatus',$userstatus)->find();
        if(!empty($data)){
            return "该账号已注册";
        }else{
            $user = [
                "userId"=>$userId,
                "userName" => $username,
                "password" => $password,
                "userstatus" => $userstatus
            ];
            return $this->insert($user);
        }
    }
}
?>